<?php 
	if (!isset($_SESSION["taikhoan"]))
	{
		header("Location: cnk-dangnhap.php");
	}
	
	include_once('Configs/paging.php');
	include_once('Configs/database.php');
	include_once('Models/Quyen.php');
    include_once('Models/ChucNang.php');
    include_once('Models/LopHocPhan.php');
	include_once('Models/HocKiNamHoc.php');
    include_once('Models/HPMoVaoHKNH.php');
    include_once('Models/LopHocPhan.php');
?>
<script src="Libraries/js/js.js"></script>

<script type="text/javascript" src="Libraries/js/jquery.min.js"></script>
<script type="text/javascript" src="Libraries/js/jquery.datepick.js"></script>
<script language="javascript">

// Chi sua ham checkField()
function checkField(){

	var maso = document.capnhatsinhvien.txtmaso.value;
	var hoten = document.capnhatsinhvien.txthoten.value;
	
	var ngaysinh = document.capnhatsinhvien.txtngaysinh.value;
	var indexphai = document.capnhatsinhvien.cbophai.selectedIndex;
	var sodt = document.capnhatsinhvien.txtsodt.value;
	//var diachi = document.capnhatsinhvien.txtdiachi.value;
	var email = document.capnhatsinhvien.txtemail.value;
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; // filter = /^\w+@\w+\.\w+$/;
	var regDT=/^[0-9]{9,11}$/;
	
	if (maso == "" || hoten== "" || ngaysinh == "" || sodt == "" || email == "")
	{
		alert("Xin vui lòng nhập đầy đủ thông tin được yêu cầu!");
		return false;
	}
	else if (isNaN(hoten)==false) {
		alert("Họ tên không hợp lệ (có ký số)!");
		return false;
	}
	else if (hoten.length > 50){
		alert("Họ tên có độ dài không quá 40 kí tự!");
		return false;
	}
	else if (!regDT.test(sodt)) {
		alert("Số điện thoại không hợp lệ!");
		return false;
	}
	else if (sodt.length < 10 || sodt.length > 13){
		alert("Số điện thoại có độ dài từ 10 - 13 kí tự!");
		return false;
	}
	else if (isNaN(sodt)==true) {
		alert("Số điện thoại phai la so!");
		return false;
	}
	
	else if (!filter.test(email)) {
		alert("Email không đúng định dạng!");
		return false;
	}
	else if (email.length > 50){
		alert("Email có độ dài không quá 50 kí tự!");
		return false;
	}
	
	 return true;
}
function getValue(id){
		document.capnhatsinhvien.txtmaso.value=document.getElementById("maso" + id).innerHTML;
        document.capnhatsinhvien.txthoten.value=document.getElementById("hoten" + id).innerHTML;
        document.capnhatsinhvien.txtngaysinh.value=document.getElementById("ngaysinh" + id).innerHTML;
        document.capnhatsinhvien.txtsodt.value=document.getElementById("sodt" + id).innerHTML;
        document.capnhatsinhvien.txtemail.value=document.getElementById("email" + id).innerHTML;
		for(var i=0;i<document.capnhatsinhvien.cbophai.length;i++){
			if(document.capnhatsinhvien.cbophai[i].value==document.getElementById("phai" + id).innerHTML){
				document.capnhatsinhvien.cbophai.selectedIndex=i;
				break;
			}
		}
		document.capnhatsinhvien.btnxoa.disabled = false;
        //if (document.capnhatsinhvien.chkchon.checked == true){
            //document.capnhatsinhvien.chkchon.checked = false;
        //}
	
		
		
}
function confirmDelete(){
    if (confirm("Bạn có chắc muốn xóa sinh viên này khỏi danh sách ghi xác nhận không?")){
        return true;
    }
    return false;
    
}
function confirmUpdate(){
    if (confirm("Bạn có chắc muốn sửa thông tin của sinh viên này không?")){
        return true;
    }
    return false;
    
}

function empty(){
	document.capnhatsinhvien.btnxoa.disabled = true;
    //document.capnhatsinhvien.cbohocki.selectedIndex = 0;
    //document.capnhatsinhvien.cbohp.selectedIndex = 0;
    //document.capnhatsinhvien.cbolophp.selectedIndex = 0;
	document.capnhatsinhvien.txtmaso.value = "";
	document.capnhatsinhvien.txthoten.value = "";
	
	document.capnhatsinhvien.txtngaysinh.value = "";
	document.capnhatsinhvien.cbophai.selectedIndex = 0;
	document.capnhatsinhvien.txtsodt.value = "";
	
	document.capnhatsinhvien.txtemail.value = "";
    document.capnhatsinhvien.chkchon[i].checked = false;
    /*for (var i=0; i<document.capnhatsinhvien.chkchon.length; i++){
       if ( document.capnhatsinhvien.chkchon[i].checked == true){
            document.capnhatsinhvien.chkchon[i].checked = false;
			break;   
       }
    }*/
	
	
}

$(function() {
	//$('#popupDatepicker').datepick();
	$('#inlineDatepicker').datepick({onSelect: showDate});
	$('#popupDatepicker').datepick({dateFormat: 'yyyy-mm-dd'});
	$('#popupDatepicker2').datepick({dateFormat: 'yyyy-mm-dd'});
});
 
function showDate(date) {
	alert('The date chosen is ' + date);
}

function hienThiThongTinSV(maso)
{ 
  
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
	 	alert ("Browser does not support HTTP Request")
	 	return
	}
	var url="xuliajax.php"
	url=url+"?form=capnhatsinhvien&func=hienthittsv&maso="+maso;
	url=url+"&sid="+Math.random()
    //alert("maquyen");
	xmlHttp.onreadystatechange=stateChangedForhienThiThongTinSV
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}
function stateChangedForhienThiThongTinSV() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	 { 
        var result = xmlHttp.responseText;
        if(result != "")
        {
            //alert("maquyen");
            //dsTatCaBM();
            var myArr = result.split("|");
            //alert(myArr[0]);
            document.capnhatsinhvien.txthoten.value = myArr[0];
            document.capnhatsinhvien.txtngaysinh.value=myArr[1];
            //document.capnhatcanbo.txtngaysinh.value=myArr[2];
            for(var i=0;i<document.capnhatsinhvien.cbophai.length;i++){
    		  if(document.capnhatsinhvien.cbophai[i].value==myArr[2]){
    			document.capnhatsinhvien.cbophai.selectedIndex=i;
    		  }
	       }
            
            document.capnhatsinhvien.txtemail.value=myArr[3];
            document.capnhatsinhvien.txtsodt.value=myArr[4];
            
            
           
            
           
           
	      	
          
           
        }
         
	 } 
}
</script>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="Libraries/css/jquery.datepick.css" rel="stylesheet" type="text/css"></head>
<title>Untitled Document</title>
</head>

<body>
<form name="capnhatsinhvien" method="POST">
<table align="center" class="font" width="800" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="31" class=main_1><img border="0" src="Libraries/images/tbl_left.gif" width="10" height="25" /></td>
    <td width="671" align=center class=main_1>Cập Nhật Sinh Viên Ghi Xác Nhận Cho Nhật Kí Giảng Dạy Lớp Học Phần </td>
    <td width="32" class=main_1><p align="right"><img border="0" src="Libraries/images/tbl_right.gif" width="10" height="25" /></p></td>
  </tr>
  <tr bgcolor="#dae9f3">
    <td class="border_1" colspan="3" valign="top"><table border="0" align="center">
      <tr>
        <td colspan="6">&nbsp;</td>
        </tr>
      <tr>
        <td colspan="6" align="center"><table border="0">
          <tr>
            <td>Năm học</td>
            <td><select name="cbonamhoc" onChange="document.capnhatsinhvien.cbohocki.selectedIndex = 0;" >
                <option value=" "></option>
                <?php
								$hknh = new HocKiNamHoc();
                                $result = $hknh->dsNamHoc();
                                while ($rows=mysql_fetch_array($result)){
                                    echo "<option value='".$rows['namhoc']."'";				
				                    echo ">".$rows['namhoc']."</option>";
                                }
                                if (isset($_POST['cbonamhoc'])){
                                    echo "<script language=\"javascript\">for(var i=0;i<document.capnhatsinhvien.cbonamhoc.length;i++){if(document.capnhatsinhvien.cbonamhoc[i].value=='$namhoc'){document.capnhatsinhvien.cbonamhoc.selectedIndex=i;break;}}</script>";
                                }
                                ?>
            </select></td>
            <td>Học kì</td>
            <td><select name="cbohocki" onChange="document.capnhatsinhvien.cbohp.selectedIndex = 0;document.capnhatsinhvien.submit();">
                <option value="0"></option>
                <option value="1" <?php if ($_POST['cbohocki']==1) echo "selected='selected'"; ?>>1</option>
                <option value="2" <?php if ($_POST['cbohocki']==2) echo "selected='selected'"; ?>>2</option>
                <option value="3" <?php if ($_POST['cbohocki']==3) echo "selected='selected'"; ?>>Hè</option>
            </select></td>
            <td>Học phần</td>
            <td><select name="cbohp" id="cbohp" onChange="document.capnhatsinhvien.submit();" >
              <option value=" "></option>
              <?php
                if (isset($_POST['cbohocki'])){
                    //$hphknh = new HPMoVaoHKNH();
                    //$hphknh->setNamHoc($namhoc);
                    //$hphknh->setHocKi($hocki);
                    //$result = $hphknh->dsHocPhanMoVaoHKNH();
					$hphknh = new HPMoVaoHKNH();
					$hphknh->setHocKi($hocki);
					$hphknh->setNamHoc($namhoc);
					
					
					
					$result = $hphknh->dsHocPhanDayVaoHKNHCuaCBGD($_SESSION['nmaso']);
                    while ($rows=mysql_fetch_array($result)){
                        echo "<option value='".$rows['mahp']."'";				
	                    echo ">".$rows['tenhp']."</option>";
                    }
                    if (isset($_POST['cbohp'])){
                        echo "<script language=\"javascript\">for(var i=0;i<document.capnhatsinhvien.cbohp.length;i++){if(document.capnhatsinhvien.cbohp[i].value=='$mahp'){document.capnhatsinhvien.cbohp.selectedIndex=i;break;}}</script>";
                    }
                
                }             
              ?>
            </select></td>
            <td>Nhóm</td>
            <td><select name="cbolophp" onChange="document.capnhatsinhvien.submit();">
              <option value=" "></option>
               <?php
                if (isset($_POST['cbohp'])){
                    //$lophp = new LopHocPhan();
                    //$lophp->setNamHoc($namhoc);
                    //$lophp->setHocKi($hocki);
                    //$lophp->setMaHP($mahp);
                    //$result = $lophp->dsLopHPMoTrongHKNHCuaHP();
					$lophp = new LopHocPhan();
					$lophp->setNamHoc($namhoc);
					$lophp->setHocKi($hocki);
					$lophp->setMaHP($mahp);
					$lophp->setMaSo($_SESSION['nmaso']);
					$result = $lophp->dsLopHPCuaHPMoTrongHKNHCuaCBGD();
                    while ($rows=mysql_fetch_array($result)){
                        echo "<option value='".$rows['malophp']."'";				
	                    echo ">".$rows['kihieu']."</option>";
                    }
                    if (isset($_POST['cbolophp'])){
                        echo "<script language=\"javascript\">for(var i=0;i<document.capnhatsinhvien.cbolophp.length;i++){if(document.capnhatsinhvien.cbolophp[i].value=='$malophp'){document.capnhatsinhvien.cbolophp.selectedIndex=i;break;}}</script>";
                    }
                
                }             
              ?>
             
            </select></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td width="128" align="right">MSSV</td>
        <td width="71"><input name="txtmaso" type="text" id="txtmaso" size="8" onKeyUp="hienThiThongTinSV(this.value);"/>
          <?PHP 
				if (isset($_POST['txtmaso'])){
                    echo "<script language=\"javascript\">document.capnhatsinhvien.txtmaso.value='$maso'</script>";
                }
			?></td>
        <td width="53" align="right">H&#7885; Tên</td>
        <td width="150"><input name="txthoten" type="text" id="txthoten" size="25"/>
          <?php 
				if (isset($_POST['txthoten'])){
                    echo "<script language=\"javascript\">document.capnhatsinhvien.txthoten.value='$hoten'</script>";
                }
			?></td>
        <td width="85" align="right">Ng&agrave;y Sinh</td>
        <td width="135"><input name="txtngaysinh" type="text" id="popupDatepicker" size="12" maxlength="12" readonly="true" style="background-color: #cccccc;"/>
          <?php 
				if (isset($_POST['txtngaysinh'])){
                    echo "<script language=\"javascript\">document.capnhatsinhvien.txtngaysinh.value='$ngaysinh'</script>";
                }
			?></td>
      </tr>
      <tr>
        <td align="right">Ph&aacute;i</td>
        <td><select name="cbophai">
          <option value=""></option>
          <option value="1"<?php if ($_POST['cbophai']=='1') echo "selected='selected'"; ?>>Nam</option>
          <option value="0"<?php if ($_POST['cbophai']=='0') echo "selected='selected'"; ?>>Nữ</option>
        </select></td>
        <td align="right">S&#7889; &#272;T</td>
        <td><input name="txtsodt" type="text" id="txtsodt" size="15"/>
          <?php 
				if (isset($_POST['txtsodt'])){
                    echo "<script language=\"javascript\">document.capnhatsinhvien.txtsodt.value='$sodt'</script>";
                }
			?></td>
        <td align="right">Email</td>
        <td><input name="txtemail" type="text" id="txtemail" size="30"/>
          <?php 
				if (isset($_POST['txtemail'])){
                    echo "<script language=\"javascript\">document.capnhatsinhvien.txtemail.value='$email'</script>";
                }
			?></td>
      </tr>
     
      <tr>
        <td colspan="6" align="center"><input type="button" name="btntaomoi" value="Tạo mới" class="button_1" onClick="empty();"/>&nbsp;
			<input type="submit" name="btnthem" value="Thêm" class="button_1" onClick="return checkField();"/>&nbsp;
			<input type="submit" name="btnsua" value="Sửa" class="button_1" onClick="return checkField();"/>&nbsp;
			<input type="submit" name="btnxoa" value="Xóa" class="button_1" disabled="true" onClick="return confirmDelete();"/>		</td>
        </tr>
    </table></td>
  </tr>
</table>
<br/>
<br/>

 <?php
if (strlen($malophp) > 0 ) 
{
    // Xử lý hiện thị mật kgẩu
    //if (isset($_POST['btnxem'])){
	$db = new database();
    $query = "select a.maso, hoten,ngaysinh, phai, email, sodt ";
    $query .= "from SinhVien a, LopHocPhan b, SinhVienGhiNhatKi c ";
    $query .= "where  b.malophp='".$malophp."' and a.maso = c.maso and b.malophp = c.malophp";
    $db->setQuery($query);
    //$num = mysql_num_rows($result);
	$result = $db->fetchAll();
        echo "<table align='center' class='font' width='800' border='0' cellspacing='0' cellpadding='0'>";
          echo "<tr>";
            echo "<td class='main_1'><img border='0' src='Libraries/images/tbl_left.gif' width='10' height='25' /></td>";
            echo "<td align='center' class='main_1'>Thông tin mật khẩu</td>";
            echo "<td class='main_1'><p align='right'><img border='0' src='Libraries/images/tbl_right.gif' width='10' height='25' /></p></td>";
          echo "</tr>";
          echo "<tr >";
            echo "<td class='border_1' colspan='3' valign='top'><table width='800' class='border_1' style='border:none' id='tbmain' cellpadding='0' cellspacing='0'>";
              echo "<tr>";
                echo "<td width='30' align='center' class='main_3'>STT</td>";
                echo "<td width='60' align='center' class='main_3'>MSSV</td>";
                echo "<td width='150' align='center' class='main_3'>Họ Tên</td>";
                echo "<td width='90' align='center' class='main_3'>Ngày Sinh</td>";
                echo "<td width='80' align='center' class='main_3'>Giới Tính</td>";
                echo "<td width='100' align='center' class='main_3'>Số ĐT</td>";
                echo "<td width='150' align='center' class='main_3'>Email</td>";
				echo "<td width='80' align='center' class='main_3'>Mật Khẩu</td>";
        		echo "<td width='50' align='center' class='main_3'>Chọn</td>";
                
                echo "</tr>";
             
          
        	
        	 	
        		
        	
        		$num=mysql_num_rows($result);
                if ($num > 0){
                    $i=0;
            		$ci=0;
            		
            		while($row=mysql_fetch_array($result))
            		{
      		            
            			$i++;
            			$ci=2-$i%2;
            			
            			echo "<tr>";
            			echo "<td align='center' class='main_3'>".$i."</td>";
                        echo "<td class='level_1_$ci' align='center'><div id='maso$i'>".$row['maso']."</div></td>";
            			echo "<td class='level_1_$ci' align='left'><div id='hoten$i'>".$row['hoten']."</div></td>";
            			echo "<td class='level_1_$ci' align='center'><div id='ngaysinh$i'>".$row['ngaysinh']."</div></td>";
                        echo "<td class='level_1_$ci' align='center'><div id='phai$i'>".$row['phai']."</div></td>";
                        echo "<td class='level_1_$ci' align='center'><div id='sodt$i'>".$row['sodt']."</div></td>";
                        echo "<td class='level_1_$ci' align='center'><div id='email$i'>".$row['email']."</div></td>";
						if( isset($_POST['btnthem']) and $row['maso'] == $_POST['txtmaso'])
						{
            				echo "<td class='level_1_$ci' align='center'><div id='matkhau$i'>".$mk."</div></td>";
            			}
						else
						{
							echo "<td class='level_1_$ci' align='center'><div id='matkhau$i'></div></td>";
						}
            			echo "<td class='level_1_$ci' align='center'><input type='radio' name='chkchon' value='$i' onClick='getValue(this.value);' ></td>";
            		
            			echo "</tr>";
            		
            			
            		}
                    
                }
                else{
                    echo "<tr>";
        			
                        echo "<td class='level_1_1' align='center' colspan='8'>Chưa có sinh viên nào ghi xác nhận</td>";
        			
        		
        			
        		
        			echo "</tr>";
                    
                }
        		
        		
        	
        
        
              
            echo "</table></td>";
          echo "</tr>";
        echo "</table>";
    //}
}
?>
</form>
</body>
</html>
